home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / basic / ace24dist.lha / ace24.lha / prgs / Turtle / tree.b < prev   
Text File  |  1996-09-10  |  821b  |  60 lines

  1. '...recursive binary tree using turtle graphics
  2.  
  3. sub tree(n)
  4.   if n<5 then exit sub 
  5.    turnright 30
  6.    forward n
  7.    tree(n*.75)
  8.    back n
  9.    turnleft 60
  10.    forward n
  11.    tree(n*.75)
  12.    back n
  13.    turnright 30
  14. end sub
  15.  
  16. sub usage
  17.   print "usage: tree <depth>"
  18. end sub
  19.  
  20. if argcount<>1 then 
  21.   ask.depth=-1
  22. else
  23.   ask.depth=0
  24.   x$=arg$(1)
  25.   if x$="?" then
  26.     usage
  27.     input "enter depth: ",depth
  28.   else
  29.     depth=val(x$)    '..get depth
  30.   end if
  31. end if
  32.  
  33. screen 1,640,200,2,2
  34. window 1,,(0,10)-(640,200),32,1
  35. font "topaz",8
  36. color 1,0
  37.  
  38.  cls
  39.  locate 3,1
  40.  if ask.depth then 
  41.     input "enter depth: ",depth
  42.     cls
  43.     locate 3,1
  44.  end if
  45.  print "depth of tree is"
  46.  print depth 
  47.  
  48.  penup
  49.  setxy 320,150
  50.  pendown
  51.  
  52.  tree(depth)
  53.  
  54.  locate 23,1
  55.  print "press 'q' to quit...";
  56.  while ucase$(inkey$)<>"Q":wend
  57.  
  58. window close 1
  59. screen close 1
  60.